package com.wjv.example.common;

import java.io.Serializable;

/**
 * <p>Title: ResultInfo</p>
 *
 * @author wjv
 * @date Create in 2021/3/18 11:38
 * @description
 */
public class ResultInfo implements Serializable {
    private int code;

    private String msg;

    private Object data;

    public ResultInfo() {
    }

    public static ResultInfo success(Object data) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(ResultCode.SUCCESS.getCode());
        resultInfo.setData(data);
        resultInfo.setMsg("success");
        return resultInfo;
    }

    public static ResultInfo success(String msg, Object data) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(ResultCode.SUCCESS.getCode());
        resultInfo.setData(data);
        resultInfo.setMsg(msg);
        return resultInfo;
    }

    public static ResultInfo fail(String msg) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(ResultCode.FAIL.getCode());
        resultInfo.setMsg(msg);
        return resultInfo;
    }

    public static ResultInfo fail(int code, String msg) {
        ResultInfo resultInfo = new ResultInfo();
        resultInfo.setCode(code);
        resultInfo.setMsg(msg);
        return resultInfo;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultInfo{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
